/*-
 * Copyright (c) 2007 Microsoft
 * All rights reserved.
 */

#pragma once

namespace Microsoft{
    namespace ComputeCluster{
        namespace MpiNet{
            using namespace System::Threading;
            using namespace System;

            ref class MPIWaitHandle : public WaitHandle
            {
            private:
                MPI_Request request;

            public:
                MPIWaitHandle(MPI_Request request)
                {
                    this->request = request;
                }

                virtual bool WaitOne() override
                {
                    MPI_Request request0;
                    int ret;

                    request0 = this->request;
                    ret = MPI_Wait(&request0, MPI_STATUS_IGNORE);
                    if (ret != MPI_SUCCESS)
                            throw gcnew MPIException(ret);

                    return true;
                }
            };
        }
    }
}